import { InjectableObject } from "../../inject";
import { ECSWorld } from "../ECSWorld";

export abstract class ECSSystem extends InjectableObject {

    get name(): string {
        return this.constructor.name;
    }

    // 系统是否可用
    enabled: boolean = true;

    // 执行优先级
    priority: number = 0;

    // 是否运行中
    isRunning: boolean = false;

    private ecsWorld: ECSWorld | undefined;

    get ecs(): ECSWorld {
        if (!this.ecsWorld) {
            throw new TypeError("[ECS] System.ecs is undefined");
        }
        return this.ecsWorld;
    }

    set ecs(ecs: ECSWorld | undefined) {
        this.ecsWorld = ecs;
    }

    // 载入
    async load() { }

    // 卸载
    unload() { }

    start(): void {
        if (!this.isRunning) {
            this.isRunning = true;
        }
    }

    stop(): void {
        if (this.isRunning) {
            this.isRunning = false;
        }
    }

    update(dt: number) {

    }

}